package test;
import java.io.File;

import javax.swing.Icon;
import javax.swing.filechooser.FileSystemView;

import org.eclipse.core.internal.resources.Folder;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class SystemFileIconLoad {

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new RowLayout());

    Label label = new Label(shell, SWT.NONE);
    Image image = null;
    
    Program p = Program.findProgram(".txt");
    ImageData data = p.getImageData();
    image = new Image(display, data);
    label.setImage(image);

    p = Program.findProgram(".pdf");
    if(p != null) {
	    data = p.getImageData();
	    image = new Image(display, data);
	    label = new Label(shell, SWT.NONE);
	    label.setImage(image);
    }

    p = Program.findProgram(".doc");
    data = p.getImageData();
    image = new Image(display, data);
    label = new Label(shell, SWT.NONE);
    label.setImage(image);
    
    
    try {
	    FileSystemView view = FileSystemView.getFileSystemView();
	    File lnkFile = File.createTempFile("icon", ".lnk");
	    Icon icon = view.getSystemIcon(lnkFile);
    } catch(Exception e) {
    	e.printStackTrace();
    }
    
    String[] extensions = Program.getExtensions();
    
    for(String e : extensions) {
    	System.out.println(e);
    }
    
    label.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    if (image != null)
      image.dispose();
    display.dispose();
  }

}